package com.qiang.work.test08;

import org.apache.log4j.pattern.IntegerPatternConverter;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Demo01 {
    public static void main(String[] args) throws DocumentException {
        //创建解析器
        SAXReader saxReader = new SAXReader();
        //解读问价
        Document document = saxReader.read("day18\\student.xml");

        //获取根标签
        Element rootElement = document.getRootElement();

        //获取指定的子标签
        List<Element> student = rootElement.elements("student");

        //创建集合，存储学生
        ArrayList<Student> list = new ArrayList<Student>();

        //获取id属性
        for (Element element : student) {
            String id = element.attributeValue("id");
            String name = element.elementText("name");
            //String age = element.elementText("age");
            String sex = element.elementText("sex");
            Student student1 = new Student(id, name, sex);
            list.add(student1);
        }
        for (Student student2 : list) {
            System.out.println(student2);
        }
    }
}
